import { GTextFormat } from "../../../common/GTextFormat";
import { FontUtil } from "../../../common/font/FontUtil";
import { TweenMax } from "../../../../com/greensock/TweenMax";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { FilterConst } from "../../../component/gconst/FilterConst";
import { 2 } from "../../../../0/2";
type int = number;
//class NoticeItem
    
    export  class NoticeItem /* flash.display.Sprite */
    {
        constructor()
        {
            
            this._bmpDict = [];
            this._lineDict = [];
            this._widthDict = [];
            this._matix = new Object /* flash.geom.Matrix */();
            mouseEnabled = false;
            mouseChildren = false;
            cacheAsBitmap = true;
            this._textField = new Object /* flash.text.TextField */();
            this._textField.selectable = false;
            this._textField.multiline = true;
            this._textField.wordWrap = true;
            this._textField.width = this.WIDTH;
            var loc1=new GTextFormat(FontUtil.songtiName, 14, 16776960, false, null, null, null, null, flash.text.TextFormatAlign.LEFT, null, null, null, 4);
            loc1.letterSpacing = 2;
            this._textField.defaultTextFormat = loc1;
            this._textField.autoSize = flash.text.TextFieldAutoSize.LEFT;
            return;
        }

        /* internal  */onInEnd(): void
        {
            this._timerKey = flash.utils.setTimeout(this.timerOutHandler, 3000);
            return;
        }

        public onOutEnd(): void
        {
            if (this._endFun != null) 
            {
                this._endFun.call(this, this);
            }
            return;
        }

        /* internal  */onHideEnd(): void
        {
            this._hideIng = false;
            if (this._hideCallBack != null) 
            {
                this._hideCallBack.call(this, this);
            }
            return;
        }

        /* internal  */timerOutHandler(): void
        {
            var loc1=0;
            var loc2=null;
            while (loc1 < numChildren) 
            {
                loc2 = this._bmpDict[loc1];
                if (loc1 != 0) 
                {
                    this._outTween = TweenMax.to(loc2, 0.2, {"alpha": 2});
                }
                else 
                {
                    this._outTween = TweenMax.to(loc2, 0.2, {"alpha": 2, "onComplete": this.onOutEnd});
                }
                ++loc1;
            }
            return;
        }

        public updateData(arg1: string, arg2: Function, arg3: int=70, arg4: Boolean=true): void
        {
            var loc1=0;
            var loc3=null;
            this.disposed = false;
            this._line = 0;
            this._height = 0;
            this._matix.ty = 0;
            this._lineDict.splice(0);
            this._widthDict.splice(0);
            this._textField.htmlText = HTMLUtil.addColor(arg1, "#ffff00");
            this._textField.height = this._textField.textHeight;
            var loc2=this._textField.numLines;
            while (loc1 < loc2) 
            {
                loc3 = this.getBmpByLine(loc1);
                addChild(loc3);
                ++loc1;
            }
            this.resetPosx();
            this._endFun = arg2;
            this.onInEnd();
            return;
        }

        /* internal  */getBmpByLine(arg1: int): Object /* flash.display.Bitmap */
        {
            var loc3=null;
            var loc1=this.getLineMetrics(arg1);
            var loc2=this._bmpDict[arg1];
            if (!loc2) 
            {
                var loc4;
                this._bmpDict[arg1] = loc4 = new Object /* flash.display.Bitmap */();
                loc2 = loc4;
                loc2.filters = [FilterConst.noticeItemFilter2, FilterConst.noticeItemFilter];
            }
            loc2.alpha = 1;
            loc2.bitmapData = this.getBmpdByLine(arg1, loc1);
            if (arg1 % 3 == 0) 
            {
                var loc5=((loc4 = this)._line + 1);
                loc4._line = loc5;
            }
            if (arg1 != 0) 
            {
                loc3 = this.getLineMetrics((arg1 - 1));
            }
            loc2.x = this.getLineSumWidth(this._line);
            if (loc3) 
            {
                if (this._line > 1) 
                {
                    loc2.y = (this._line - 1) * loc3.height;
                }
                else 
                {
                    loc2.y = 0;
                }
            }
            else 
            {
                loc2.y = 0;
            }
            if (!this._lineDict[(this._line - 1)]) 
            {
                this._lineDict[(this._line - 1)] = [];
            }
            this._lineDict[(this._line - 1)].push(loc2);
            if (!this._widthDict[(this._line - 1)]) 
            {
                this._widthDict[(this._line - 1)] = 0;
            }
            this._widthDict[(this._line - 1)] = this._widthDict[(this._line - 1)] + loc1.width;
            return loc2;
        }

        /* internal  */getBmpdByLine(arg1: int, arg2: Object /* flash.text.TextLineMetrics */): Object /* flash.display.BitmapData */
        {
            var loc1=arg2.height;
            var loc2=arg2.width;
            this._matix.ty = (-arg1) * loc1;
            var loc3;
            (loc3 = new Object /* flash.display.BitmapData */(loc2, loc1, true, 0)).draw(this._textField, this._matix);
            return loc3;
        }

        /* internal  */getLineMetrics(arg1: int): Object /* flash.text.TextLineMetrics */
        {
            var index: int;
            var tme: Object /* flash.text.TextLineMetrics */;

            var loc1;
            tme = null;
            index = arg1;
            try 
            {
                tme = this._textField.getLineMetrics(index);
            }
            catch (e)
            {
                tme = new Object /* flash.text.TextLineMetrics */(0, 20, 20, 0, 0, 0);
            }
            return tme;
        }

        /* internal  */resetPosx(): void
        {
            var loc1=0;
            var loc2=0;
            var loc3=0;
            var loc4=0;
            var loc5=null;
            var loc6=null;
            while (loc2 < this._line) 
            {
                loc1 = (this.width - this._widthDict[loc2]) / 2;
                loc4 = (loc5 = this._lineDict[loc2]).length;
                loc3 = 0;
                while (loc3 < loc4) 
                {
                    loc6 = loc5[loc3];
                    loc6.x = loc6.x + loc1;
                    ++loc3;
                }
                ++loc2;
            }
            return;
        }

        /* internal  */getLineSumWidth(arg1: int): int
        {
            if (this._widthDict.length >= arg1) 
            {
                return this._widthDict[(arg1 - 1)];
            }
            return 0;
        }

        public easeHide(arg1: Function): void
        {
            this._hideIng = true;
            this._hideCallBack = arg1;
            this.onHideEnd();
            return;
        }

        public killInEase(): void
        {
            this.onInEnd();
            return;
        }

        public dispose(): void
        {
            var loc1=null;
            this._textField.text = "";
            this._hideCallBack = null;
            this._hideIng = false;
            this._endFun = null;
            flash.utils.clearTimeout(this._timerKey);
            if (this._outTween && this._outTween.active) 
            {
                this._outTween.kill();
            }
            while (0 < numChildren) 
            {
                loc1 = removeChildAt(0) as Object /* flash.display.Bitmap */;
                loc1.bitmapData.dispose();
                loc1.bitmapData = null;
            }
            this.disposed = true;
            return;
        }

        public updatePosY(arg1: int): void
        {
            this.y = arg1;
            return;
        }

        public get hideIng(): Boolean
        {
            return this._hideIng;
        }

        public /* override */ get height(): number
        {
            if (this._height == 0) 
            {
                this._height = this._line * 20;
            }
            return this._height;
        }

        public /* override */ get width(): number
        {
            return 810;
        }

        /* internal */ /* const */WIDTH: int=270;

        /* internal */ /* var */_bmpDict: Array<any>;

        /* internal */ /* var */_lineDict: Array<any>;

        /* internal */ /* var */_widthDict: Array<any>;

        /* internal */ /* var */_textField: Object /* flash.text.TextField */;

        /* internal */ /* var */_matix: Object /* flash.geom.Matrix */;

        /* internal */ /* var */_height: int;

        /* internal */ /* var */_line: int;

        /* internal */ /* var */_timerKey: int;

        /* internal */ /* var */_outTween: TweenMax;

        /* internal */ /* var */_endFun: Function;

        /* internal */ /* var */_hideCallBack: Function;

        /* internal */ /* var */_hideIng: Boolean;

        public /* var */disposed: Boolean;
    }
